package top.jiachunlei.proxy.lesson1;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 基于JDK的动态代理就需要知道两个类：1.InvocationHandler（接口）、2.Proxy（类）
 * @author 朝花不迟暮
 * @version 1.0
 * @date 2020/12/4 21:06
 */
public class SubjectProxy implements InvocationHandler
{
    private Subject subject;

    public SubjectProxy(Subject subject)
    {
        this.subject = subject;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
    {
        System.out.println("--------------begin-------------");
        Object invoke = method.invoke(subject, args);
        System.out.println("--------------end-------------");
        return invoke;
    }
}
